package com.jeejam.product.dubbo;

import com.alibaba.dubbo.config.annotation.Service;
import com.jeejam.framework.base.pojo.TreePager;
import com.jeejam.product.sdk.api.IProductCategoryService;
import com.jeejam.product.sdk.dto.ProductCategoryDto;
import com.jeejam.product.service.CategoryService;
import com.jeejam.util.ShopBeanBuildUtil;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by JACKEY on 2016/3/26.
 */
@Service(version = "1.0.0")
public class ProductCategoryDubboService implements IProductCategoryService {

    @Resource
    private CategoryService categoryService;

    @Override
    public List<ProductCategoryDto> selectRoot() {
        return ShopBeanBuildUtil.slmCopyBeanList(categoryService.selectRoot(), ProductCategoryDto.class);
    }

    @Override
    public List<ProductCategoryDto> selectRootWithoutChildren() {
        return ShopBeanBuildUtil.slmCopyBeanList(categoryService.selectRootWithoutChildren(), ProductCategoryDto.class);
    }

    @Override
    public List<ProductCategoryDto> selectRootByPage(int page, int pageSize) {
        return ShopBeanBuildUtil.slmCopyBeanList(categoryService.selectRootByPage(page, pageSize), ProductCategoryDto.class);
    }

    @Override
    public List<ProductCategoryDto> selectChildren(int catId) {
        return ShopBeanBuildUtil.slmCopyBeanList(categoryService.selectChildren(catId), ProductCategoryDto.class);
    }

    @Override
    public List<ProductCategoryDto> selectSubChildren(int parentId) {
        return ShopBeanBuildUtil.slmCopyBeanList(categoryService.selectSubChildren(parentId), ProductCategoryDto.class);
    }

    @Override
    public TreePager getTreePager(int currentPage, int pageSize) {
        return categoryService.getTreePager(currentPage, pageSize);
    }

    @Override
    public int countsWithRoot() {
        return categoryService.countsWithRoot();
    }

    @Override
    public void deleteWithChildren(int id) {
        categoryService.deleteWithChildren(id);
    }

    @Override
    public List<ProductCategoryDto> showIndex() {
        return ShopBeanBuildUtil.slmCopyBeanList(categoryService.showIndex(), ProductCategoryDto.class);
    }

    @Override
    public ProductCategoryDto selectRootByCategoryId(int catId) {
        return ShopBeanBuildUtil.slmCopyBean(categoryService.selectRootByCategoryId(catId), ProductCategoryDto.class);
    }

    @Override
    public ProductCategoryDto getById(int id) {
        return ShopBeanBuildUtil.slmCopyBean(categoryService.findById(id), ProductCategoryDto.class);
    }
}
